Add support for cross-compiling, use stable release channel
authorXimin Luo <infinity0@debian.org>
Mon, 1 May 2017 18:40:30 +0000 (20:40 +0200)
committerXimin Luo <infinity0@debian.org>
Mon, 1 May 2017 18:40:30 +0000 (20:40 +0200)
debian/control
debian/rules

index 05612b4cdc7748e86ac40a274af491b1afead5a5..4d89cba475b5586d83b4d4a478a4bb0bcb6ed66a 100644 (file)
@@ -10,12 +10,14 @@ Build-Depends: debhelper (>= 9.20141010),
                rustc (>= 1.16),
                pkg-config,
                cmake,
-               cargo (>= 0.7.0) <!pkg.cargo.mkstage0>,
+               cargo (>= 0.13.0) <!pkg.cargo.mkstage0>,
                python-dulwich <pkg.cargo.mkstage0>,
                python-pytoml <pkg.cargo.mkstage0>,
                ca-certificates,
                bash-completion,
                libcurl4-gnutls-dev | libcurl4-openssl-dev,
+# Direct dependency needed for cross-compiling
+               libstd-rust-dev,
                libssh2-1-dev,
                libgit2-dev (>= 0.25.1),
                libhttp-parser-dev,
index e398a8a217305da1229190a81ee3791c02cd8995..8173942b260242fe0901ca69167108da73650306 100755 (executable)
@@ -5,6 +5,12 @@ include /usr/share/dpkg/architecture.mk
 include /usr/share/dpkg/buildflags.mk
 include /usr/share/rustc/architecture.mk
 
+# For cross-compiling; perhaps we should add this to dh-cargo or debcargo
+export PKG_CONFIG = $(DEB_HOST_GNU_TYPE)-pkg-config
+export PKG_CONFIG_ALLOW_CROSS = 1
+RUSTFLAGS += -C linker=$(DEB_HOST_GNU_TYPE)-gcc
+
+# Pass on dpkg-buildflags stuff
 RUSTFLAGS += $(foreach flag,$(LDFLAGS),-C link-arg=$(flag))
 export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS RUSTFLAGS
 
@@ -21,7 +27,7 @@ override_dh_auto_configure:
 ifneq ($(filter pkg.cargo.mkstage0,$(DEB_BUILD_PROFILES)),)
        # NOTE: this very likely doesn't work any more, see bootstrap.py for details
        # Instead, you can try to bootstrap by setting PATH to a binary cargo
-       # downloaded from upstream, or by (TODO) cross-compiling.
+       # downloaded from upstream; or by cross-compiling, see "build-cross" below
        # Preserved in case someone wants to resurrect it later:
        # Bootstrap cargo stage0
        ./debian/bootstrap.py \
@@ -45,11 +51,16 @@ endif
                --disable-debug \
                --enable-optimize \
                --local-rust-root=/usr \
-               --cargo=$(CURDIR)/cargo-stage0
+               --release-channel=stable \
+               --cargo=$(CURDIR)/cargo-stage0 \
+               --build=$(DEB_BUILD_RUST_TYPE) \
+               --host=$(DEB_HOST_RUST_TYPE) \
+               --target=$(DEB_TARGET_RUST_TYPE)
 
-override_dh_auto_build:
-       # Build final cargo binary and docs
-       $(MAKE)
+override_dh_auto_build-arch:
+       RUST_BACKTRACE=1 $(MAKE)
+
+override_dh_auto_build-indep:
 ifeq (,$(findstring nodoc,$(DEB_BUILD_PROFILES)))
        $(MAKE) doc
        cd target/doc/ && rm -f jquery.js && ln -s /usr/share/javascript/jquery/jquery.js
@@ -70,3 +81,11 @@ override_dh_auto_clean:
                        $(CURDIR)/config.stamp \
                        $(CURDIR)/Makefile \
                        $(CURDIR)/cargo-stage0
+
+build-cross:
+       DEB_BUILD_OPTIONS=nocheck sbuild --profiles=nocheck \
+         --build-failed-commands '%SBUILD_SHELL' \
+         --add-depends=libc-dev:$(DEB_HOST_ARCH) \
+         $(EXTRA_SBUILD_FLAGS) \
+         --host=$(DEB_HOST_ARCH) \
+         --no-arch-all .